<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="org.springframework.util.StringUtils"%>
<%@page import="ext.generic.util.Generic"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	//属性文件路径
	String filePath = "/ext/tianma/cfg/TianmaPro.properties";
	String path = request.getContextPath();
	Object cause = Generic.getStrFromProperties(
			"borrow.applyCause", filePath);
	List<String> list = new ArrayList<String>();
	if(cause != null){
		String causeStr = cause.toString();
		if(!"".equals(causeStr) && causeStr != null){
	        String[] causeArr = causeStr.split(";");
	        for (int i = 0; i < causeArr.length;i++){
	        	list.add(causeArr[i]);
	        }
		}
	}
	
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>图文档借阅</title>
<script type="text/javascript" src="../../javascript/jquery.min.js"></script>
<script type="text/javascript">
	maximizeWindow();
	function maximizeWindow(){
	    var offset = (navigator.userAgent.indexOf("Mac") != -1 || navigator.userAgent.indexOf("Gecko") != -1 ||
	    navigator.appName.indexOf("Netscape") != -1) ? 0 : 4;
	    window.moveTo(300, 100);
	    window.resizeTo(740, 510);
	}
	$(window).resize(function () {          //当浏览器大小变化时
		var bodyWidth=$("body").width();
		var topWidth=$("#top").width();
		$("#top").css({
			"left":(bodyWidth-topWidth)/2+"px"
		})
	});
	
	
	function goBack(){
	    window.close();
	}
	$(function(){
    	$.ajaxSetup ({
    	cache: false //关闭AJAX缓存
    	});
    	});
	function submit(){
		var docNumber =document.getElementById("docName").value;
		var time =document.getElementById("time").value;
		var number =document.getElementById("number").value;
		var docName =document.getElementById("docName").value;
		var cause =document.getElementById("cause").value;
		var reason =document.getElementById("reason").value;
		if(number==null || number==''){
			alert("编号不能为空，请填写!")
			return false;
		}else if(docName==null || docName==''){
			alert("图文档名称不能为空，请选择!")
			return false;
		}else if(reason==null || reason==''){
			alert("申请理由不能为空，请填写!")
			return false;
		}
		$.ajax({
            type:"get",
            url:"<%=path %>/app/drawingSubmit/submit?docNumber="+encodeURI(docNumber)+"&time="+encodeURI(time)+"&cause="+encodeURI(cause)+"&reason="+encodeURI(reason),
            dataType:"text",
            data:{},
            success:function(data){
            	var dataObj = eval("("+data+")");
            	var stuatus = dataObj.status;
            	if("errorReview"==stuatus){
            		alert("此图文档借阅正在审核中!");
            		$("#number").val("");
            		$('#docName').empty();
            		$('#reason').val("");
        			document.getElementById("time")[0].selected=true;
        			document.getElementById("cause")[0].selected=true;
            	}else if("errorBorrow"==stuatus){
            		alert("此图文档已在借阅中!");
            		$("#number").val("");
            		$('#docName').empty();
            		$('#reason').val("");
        			document.getElementById("time")[0].selected=true;
        			document.getElementById("cause")[0].selected=true;
            	}else if("errorOwer"==stuatus){
            		alert("您已拥有此文档的借阅权限!");
            		$("#number").val("");
            		$('#docName').empty();
            		$('#reason').val("");
        			document.getElementById("time")[0].selected=true;
        			document.getElementById("cause")[0].selected=true;
            	}else if("error"==stuatus){
            		alert("提交异常，请联系管理员!");
            		$("#number").val("");
            		$('#docName').empty();
            		$('#reason').val("");
        			document.getElementById("time")[0].selected=true;
        			document.getElementById("cause")[0].selected=true;
            	}else if("success"==stuatus){
            		alert("图文档借阅申请流程已发起!");
            		window.close();
            	}
            }
		})
		 
	}
	
  	function find(){
  		var numType= document.getElementById("numType").value;
  		var number = document.getElementById("number").value;
  		if(number==null || number==''){
  			alert("编号不能为空，请填写！");
  			return false;
  		}
  		$.ajax({
            type:"get",
            url:"<%=path %>/app/borrowDra/dra?numType="+encodeURI(numType)+"&number="+encodeURI(number),
            dataType:"text",
            data:{},
            success:function(data){
            	//转化为json格式
                var dataObj = eval("("+data+")");
            	var stuatus = dataObj.status;
            	if("error"==stuatus){
            		alert("找不到此编号的图文档，请重新输入!");
            		$("#number").val("");
            		$('#docName').empty();
            	}else if("errorReleased"==stuatus){
            		alert("此编号下的图文档未发布，不能借阅!");
            		$("#number").val("");
            		$('#docName').empty();
            	}else if("errorPart"==stuatus){
            		alert("找不到此编号的物料，请重新输入!");
            		$("#number").val("");
            		$('#docName').empty();
            	}else if("errordoc"==stuatus){
            		alert("此编号物料下不存在图文档!");
            		$("#number").val("");
            		$('#docName').empty();
            	}else if("success"==stuatus){
            		$('#docName').empty();
            		//遍历输出
                	for(var s in dataObj.data){
                		$('#docName').append("<option value=\""+dataObj.data[s].number+"\">"+dataObj.data[s].name+"</option>");
                	} 
            	}
            }
		})
  	}
  	$(document).ready(function(){  
  	　　　　$('#numType').change(function(){ 
			 $("#number").val("");
			 $('#docName').empty(); 
			 $('#reason').val("");
			 document.getElementById("time")[0].selected=true;
			 document.getElementById("cause")[0].selected=true;
  	　　　　})  
  	})  
  </script>

  <style>
#top{
	height:430px;
	width:700px; 
	border:1px solid #000;
	position:absolute;
	left:12px;
	top:12px;
	
}
#top1{
	height: 49px; 
	padding-left: 30px; 
	font-weight: bold;
	font-family:verdana;
	font-size: 20px;
	padding-top: 50px;
}
#numType{
	width: 180px;
	font-size: 14px;
	height: 23px
}
#number{
	width: 218px;
}
#img1{
	width: 26px;
	height: 26px;
	line-height: 26px;
    position: absolute;
    top: 53px;
    padding-left: 6px;
}
#top2{
	height: 50px; 
	padding-left: 30px; 
	font-weight: bold;
	margin-top:10px;
	font-family:verdana;
	font-size: 20px;
}
#docName{
	width: 160px;
	font-size: 14px;
	height: 23px
}
#top3{
	height: 50px; 
	padding-left: 30px; 
	font-weight: bold;
	margin-top:10px;
	font-family:verdana;
	font-size: 20px
}
#time{
	width: 170px;
	font-size: 14px;
	height: 23px
}
#top4{
	height: 50px; 
	padding-left: 30px; 
	font-weight: bold;
	margin-top:10px;
	font-family:verdana;
	font-size: 20px
}
#cause{
	width: 180px;
	font-size: 14px;
	height: 23px
}
#top5{
	height: 50px; 
	padding-left: 26px; 
	font-weight: bold;
	margin-top:10px;
	font-family:verdana;
	font-size: 20px
}
#td1{
	height: 20px;
}
#td2{
	height: 80px;
}
#reason{
	font-size: 14px;
	height: 80px;
	width: 505px;
}
#bottom{
	height: 50px;
	text-align: right;
	margin-top:80px;
	margin-right: 30px;
}
#resetBtn{
	width: 100px; 
	height:30px;
	font-size: 15px;
	color:white; 
	background:rgba(40,148,255,1);
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#2894FF,endColorstr=#2894FF)
}
#submitBtn{
	width: 100px; 
	height:30px; 
	font-size: 15px; 
	color:white;  
	background:rgba(40,148,255,1);
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#2894FF,endColorstr=#2894FF)
}
</style>
</head>
<body style="overflow: hidden;background-color: #eee;">
   
	    <div id="top">
	                <div id="top1">
	                                 查询类型:
	                    <select id="numType" name="numType">
	                         <option value="wtPartNum">物料编号</option>
	                         <option value="wtDocNum">图文档编号</option>
	                    </select>
	             &nbsp;&nbsp;编号:
	                    <input id="number" name="number">
	                    <img id="img1" src="../../images/find.jpg" onclick="find()">
	                </div>
	                <div id="top2">
	                	图文档名称:
	                	<select id="docName">
						</select>
						 &nbsp;&nbsp;借阅时间(天):
	                   <select id="time" name="time">
	                       <option value="5">5天</option>
	                       <option value="4">4天</option>
	                       <option value="3">3天</option>
	                       <option value="2">2天</option>
	                       <option value="1">1天</option>
	                   </select>
	                </div>
	              
	              
	                <div id="top4">
	                                           申请原因:
	                   <select id="cause" name="cause">
	                       <%for(int i=0;i<list.size();i++){%>
							<option value="<%=list.get(i) %>"><%=list.get(i) %></option>
					   		<%}%>
	                   </select>
	                </div>
	                <div id="top5">
	                	<table >
			        		<tr>
			        			<td id="td1">
			        				<span>申请理由:</span>
			        			</td>
			        			<td id="td2" rowspan="2">
			        				<textarea id="reason" name="reason"></textarea>
			        			</td>
			        		</tr>
			        		<tr>
			        			<td></td>
			        			<td></td>
			        		</tr>
	        			</table>
	                </div>
	            <div id="bottom">
	                 <button id="resetBtn" name="resetBtn" onclick="goBack()">取消</button>
	                 <button id="submitBtn" name="submitBtn" onclick="submit()" >提交</button>
	            </div>
	    </div>
</body>
</html>